package com.yunyi.user.controller;

import com.yunyi.model.work.TimeShift;
import com.yunyi.response.CommonCode;
import com.yunyi.response.QueryResponseResult;
import com.yunyi.response.QueryResult;
import com.yunyi.response.ResponseResult;
import com.yunyi.user.redisSevice.RedisService;
import com.yunyi.user.response.TimeShiftResponse;
import com.yunyi.user.service.TimeShiftService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName TimeShiftController
 * @Description 班次时间表
 * @Author zhanglei
 * Date 2021/8/18 16:02
 * @Version 1.0
 **/
@RestController
@RequestMapping("/timeShiftApi")
public class TimeShiftController {
private static Logger LOGGER = LoggerFactory.getLogger(TimeShiftController.class);
    @Autowired
    private TimeShiftService timeShiftService;

    @Autowired
    private RedisService redisService;
    /**
     * @Description : 班次时间表信息获取
     * @Author : leizhang
     * @Date 11:44 下午 2021/8/20 
     * @param requestParam
     * @return com.yunyi.response.QueryResponseResult
     **/
    @GetMapping("/getTimeShiftInfo")
    public ResponseResult getTimeShiftInfo(@RequestParam Map<String,Object> requestParam) {
        try{
            Map<String,Object>  timeShiftInfos = timeShiftService.getTimeShiftInfos(requestParam);
            return new TimeShiftResponse(CommonCode.SUCCESS,timeShiftInfos);
        }catch (Exception e){
            LOGGER.error("时间表班次信息获取失败:[{}]",e.getMessage(),e);
            return new TimeShiftResponse(CommonCode.FAIL,null);
        }
    }
    /**
     * @Description : 设置每天班次的报名人数
     * @Author : leizhang
     * @Date 11:49 下午 2021/8/20
     * @param requestParam
     * @return com.yunyi.response.ResponseResult
     **/
    @PostMapping("/setTimeShiftWorkerNumber")
    public ResponseResult setTimeShiftWorkerNumber(@RequestBody Map<String,Object> requestParam) {
        try {
            /**数据格式
             * {班次类型,班次人数}
             */
            redisService.setWorkerNumber(requestParam);
            return ResponseResult.SUCCESS();
        }catch (Exception e) {
            LOGGER.error("班次信息人数限制设置错误信息:[{}]",e.getMessage(),e);
            return ResponseResult.FAIL();
        }
    }
}